# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: rubicon <rubicon@mailo.com>
pkgname=picolisp
pkgver=22.6
pkgrel=0
pkgdesc="Fast, lightweight Lisp interpreter and application server framework"
url="https://picolisp.com/"
# x86, armv7, armhf: 64-bits only
# riscv64: ftbfs
arch="all !x86 !armv7 !armhf !riscv64"
license="MIT"
depends_doc="w3m"
makedepends="
	pkgconf clang llvm readline-dev
	libffi-dev openssl1.1-compat-dev
	"
subpackages="$pkgname-doc $pkgname-bash-completion"
source="https://software-lab.de/picoLisp-$pkgver.tgz
	fix-shebang-lines.patch
	"
builddir="$srcdir"/pil21

build() {
	make -C src
}

check() {
	./pil test/lib.l -bye +
}

package() {
	mkdir -vp "$pkgdir"/usr/bin "$pkgdir"/usr/share
	ln -sv	../lib/"$pkgname"/bin/picolisp \
		../lib/"$pkgname"/bin/pil \
		"$pkgdir"/usr/bin/
	ln -sv	../lib/"$pkgname" \
		"$pkgdir"/usr/share/"$pkgname"

	# add bash completion
	mkdir -vp "$pkgdir"/usr/share/bash-completion/completions
	mv -v	lib/bash_completion \
		"$pkgdir"/usr/share/bash-completion/completions/pil

	# move documentation
	mkdir -vp "$pkgdir"/usr/share/doc
	chmod -f 644 doc/*.html doc/*/*.html loc/*
	mv -v doc "$pkgdir"/usr/share/doc/"$pkgname"
	mv -v COPYING INSTALL README "$pkgdir"/usr/share/doc/"$pkgname"/
	rm -vf man/man1/pil.1
	ln -sv picolisp.1 man/man1/pil.1
	mv -v man "$pkgdir"/usr/share/

	mkdir -vp "$pkgdir"/usr/lib
	rm -vf pil vip
	mv -v "$builddir" "$pkgdir"/usr/lib/"$pkgname"
}

doc() {
	default_doc
	mkdir -vp "$subpkgdir"/usr/lib/"$pkgname"
	ln -sv ../../share/doc/"$pkgname" "$subpkgdir"/usr/lib/"$pkgname"/doc
}

sha512sums="
c2e6db1c4c643b69983860eb4f1fa3abf8d3833497419cca15d27a7f3d6bfed6236fc1bd0adbc33626ce1ea0ff59b75b00584a78b9976ffe5ad5e123945dcce9  picoLisp-22.6.tgz
189781c56dbf6880188ece6e1d7c60e5fc54ebb9fe852084fcccdd2b79353bf04b04d73dbccd399768e4f1aa4111fc244e2553b4552a058ccd8166b979d47dce  fix-shebang-lines.patch
"
